package com.yix.util;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;

@Slf4j
@Data
public class TemplateFacade {

    /**
     * 模板基路径
     */
//    public static final String TEMPLATE_BASE_PATH= TemplateFacade.class.getResource("/docTamplete").getPath()+"/";

    public static final String TEMPLATE_HOME_PATH="/docTemplete/";

    /**
     * 模板名称
     */
    private String templateFileName;
    private InputStream is;
    /**
     * 要操作的模板文档对象
     */
    private XWPFDocument doc;


    public TemplateFacade(String templateFileName) {
        this.templateFileName = templateFileName;

        try {
            is =this.getClass().getResourceAsStream(TEMPLATE_HOME_PATH + templateFileName);
        } catch (Exception e) {
            log.error("TemplateFacade 读取模板文件失败！");
//            e.printStackTrace();
            throw new TemplateFacadeException("TemplateFacade 读取模板文件失败！path="+TEMPLATE_HOME_PATH + templateFileName);
        }

        try {
            this.doc = new XWPFDocument(is);
        } catch (IOException e) {
            log.error("TemplateFacade 创建XWPFDocument 对象失败！");
            throw new TemplateFacadeException("TemplateFacade 创建XWPFDocument 对象失败！");
        }

    }
}
